CC=gcc
CXX=g++
CFLAGS=-Wall $(DEBUG) $(DEFINITIONS) $(CINCLUDES) $(CMISCFLAGS)
CPPFLAGS=-Wall $(DEBUG) $(EXCEPTIONS) $(CPPINCLUDES) $(DEFINITIONS) $(CPPMISCFLAGS)
DEBUG=-O3 -g3
CMISCFLAGS=
CPPMISCFLAGS=-DGIMI_CLIENT_API=10303
DEFINITIONS=-DLINUX_OS -DGIMI_NO_DATATYPE_INCLUDES
EXCEPTIONS=-fexceptions -ffast-math 
CINCLUDES=-I. -I../../scanmatch -I../../mcl -I$(GDIR)utils $(BBDT_INCLUDE)
CPPINCLUDES=-I. -I../../scanmatch -I../../mcl $(OCCU_INCLUDE) -I$(GDIR)glutImageGUI -I$(GDIR)utils \
	-I$(GDIR)/ImageUtils/JPEGEncoder $(BBDT_INCLUDE) `xml2-config --cflags`

LD=g++
LDFLAGS=
LIBS=-lrt -lpthread -lGL -lGLU -lglut -ljpeg `sdl-config  --libs` -lSDL_gfx `xml2-config --libs`

GDIR=../../../../
GIMDIR=../../../..

SRCSC=
SRCSCPP= $(OCCU_SRC_CPP)

VPATH=
CPPGIMI=
CGIMI=

LNMDIR=../..

include $(LNMDIR)/BetB_dt/Makefile.bbdt

CSRCUTIL = $(GIMDIR)/utils/ownutils.c $(GIMDIR)/utils/owndebug.c
CPPIMAGEGUI = $(GIMDIR)/glutImageGUI/glutImageGUI.cpp $(GIMDIR)/ImageUtils/JPEGEncoder/JPEGEncoder.cpp

SRCSC_J2B2_GLOC=$(CSRCUTIL)
SRCSCPP_J2B2_GLOC=mapping_tool.cpp $(LNMDIR)/BetB_dt/OccuGUI.cpp \
									$(BBDT_SRC_CPP) $(CPPIMAGEGUI) $(GIMDIR)/utils/settings.cpp

SRCSCPP_LOGFILE_MATCHER=logfile-matcher.cpp $(BBDT_SRC_CPP) $(CPPIMAGEGUI) $(GIMDIR)/utils/settings.cpp

## Build GIMI and it's dependencies.
## Files are set to CGIMI and CPPGIMI variables

include Makefile.mcl
include $(LNMDIR)/map/Makefile.occu 


CGIMI += $(CMCL)
CPPGIMI += $(CPPMCL) $(CPPSM)

## Construct final lists of CPP and C objects
OBJSC_J2B2_GLOC=$(SRCSC_J2B2_GLOC:.c=.o)
OBJSCPP_J2B2_GLOC=$(SRCSCPP_J2B2_GLOC:.cpp=.opp)

OBJSC_LOGFILE_MATCHER=$(SRCSC_J2B2_GLOC:.c=.o)
OBJSCPP_LOGFILE_MATCHER=$(SRCSCPP_LOGFILE_MATCHER:.cpp=.opp)


## Define compiles and links
COMPILEC=$(CC) $(CFLAGS) $(CINCLUDES) -c
COMPILECPP=$(CXX) $(CPPFLAGS) $(CPPINCLUDES) -c
LINK=$(LD) $(LDFLAGS) $(LIBS)

.PHONY: all clean

all: mapping_tool logfile_matcher

mapping_tool: $(OBJSC_J2B2_GLOC) $(OBJSCPP_J2B2_GLOC)
						$(LINK) -o $@ $(OBJSC_J2B2_GLOC) $(OBJSCPP_J2B2_GLOC)

logfile_matcher: $(OBJSC_J2B2_GLOC) $(OBJSCPP_LOGFILE_MATCHER)
						$(LINK) -o $@ $(OBJSC_J2B2_GLOC) $(OBJSCPP_LOGFILE_MATCHER)


clean:
	rm -f *.opp *.o *.out *~ *.d *.dpp mapping_tool $(OBJ_OCCU_SLAMCL_C) $(OBJ_OCCU_SLAMCL_CPP)\
	$(OBJSC_J2B2_GLOC) $(OBJSCPP_J2B2_GLOC)

## Compile rule for all .o (.c) file
%.o:    %.c
				$(COMPILEC) -o $@ $<

## Compile rule for all .opp (.cpp) files
%.opp:	%.cpp
				$(COMPILECPP) -o $@ $<

## Dependency generation rule: For all required '.d' files
#%.d:	  %.c
#				$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
#				sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
#				rm -f $@.$$$$
#
## Dependency generation rule: For all required '.dpp' files
#%.dpp:	%.cpp
#				$(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \
#				sed 's,\($*\)\.o[ :]*,\1.opp $@ : ,g' < $@.$$$$ > $@; \
#				rm -f $@.$$$$
#
#%.h:	%.h
#
# Include dependency rules
#-include $(SRCSCPP:.cpp=.dpp) $(CPPGIMI:.cpp=.dpp)
#-include $(SRCSC:.c=.d) $(CGIMI:.c=.d)
